package com.stu.Demo;

import com.stu.entity.Dept;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author zy
 * @date 2025/3/3 15:15
 */
public class JDBCDemo3 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

        try(Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb?useSSL=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai",
                "root", "root");
            PreparedStatement ps = conn.prepareStatement("insert into dept values(?,?,?)")){

            Dept dept = new Dept(80,"人事部","北京");
            ps.setInt(1, dept.getDeptno());
            ps.setString(2, dept.getDname());
            ps.setString(3, dept.getLoc());

            ps.executeUpdate();

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
